package domain;

import java.text.DecimalFormat;

public class Balance {
	private String currency;
	private String balance;
	private DecimalFormat thousandFormat = new DecimalFormat("000");

	public Balance(String balance) {
	    this.currency = "RMB";
		this.balance = balance;
	}
	public String toString(){
		String dot = balance.substring(balance.indexOf("."));
		int original = (int) Double.parseDouble(balance);
		StringBuffer str = new StringBuffer().append(format(original));
		for(int others = original/1000;  others != 0; others/=1000){
			str.insert(0,",");
			str.insert(0,format(others));
		}
		str.append(dot);
		return currency + " " + str.toString();
	}

	private String format(int i) {
		return (i < 1000)? String.valueOf(i) :thousandFormat.format(i%1000);
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getBalance() {
		return balance;
	}

	public void setBalance(String balance) {
		this.balance = balance;
	}
	
	
}
